package com.ruoyi.common.utils.email;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @Author xiaom
 * @Date 2021/3/26 16:58
 * @Version 1.0.0
 * @Description <>
 **/
@Component
@Slf4j
public class EmailUtils {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${mail.fromMail.addr}")
    private String from;

    public void sendSimpleMail(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        try {
            mailSender.send(message);
            log.info("邮件发送成功 tp:[{}] subject:[{}] content:[{}]",to,subject,content);
        } catch (Exception e) {
            log.error("发送简单邮件时发生异常！", e);
        }
    }

}
